package com.primb.bench.common.viewmodel;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.primb.bench.R;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chen on 2017/6/19.
 * 功能描述：
 */

public class ViewCommitEntity {
    public static int[] BTN_COMMIT_BG = {R.drawable.shape_yes_btn,
            R.drawable.shape_edit_btn,
            R.drawable.shape_back_btn,
            R.drawable.shape_no_btn};
    private List<BtnViewEntity> btnViewEntityList;

    public List<BtnViewEntity> getBtnViewEntityList() {
        return btnViewEntityList;
    }

    public void setBtnViewEntityList(List<BtnViewEntity> btnViewEntityList) {
        this.btnViewEntityList = btnViewEntityList;
    }

//    public void setViewListForEntity(List<ApprovalDetailEntity.MainDataBeanX.MainDataBean.ButtonGroupBean> buttonGroup) {
//        btnViewEntityList = new ArrayList<>();
//        for (int i = 0; i < buttonGroup.size(); i++) {
//            BtnViewEntity btnViewEntity = new BtnViewEntity(buttonGroup.get(i).getButtonName(), buttonGroup.get(i).getButtonId(), buttonGroup.get(i).getButtonType());
//            btnViewEntityList.add(btnViewEntity);
//        }
//    }

    public void addView(Context context, ViewGroup viewGroup, View.OnClickListener mListener) {
        AutoLinearLayout layout = new AutoLinearLayout(context);
        layout.setOrientation(LinearLayout.HORIZONTAL);
        for (int i = 0; i < btnViewEntityList.size(); i++) {
            Button buttonAdd = new Button(context);
            if (btnViewEntityList.get(i).getStateId() == null || btnViewEntityList.get(i).getStateId().equals("")) {
                buttonAdd.setBackgroundResource(R.color.gray_efefef);
            } else if (btnViewEntityList.get(i).getStateId().equals("1")) {
                buttonAdd.setBackgroundResource(BTN_COMMIT_BG[0]);
            } else if (btnViewEntityList.get(i).getStateId().equals("4")) {
                buttonAdd.setBackgroundResource(BTN_COMMIT_BG[3]);
            } else if (btnViewEntityList.get(i).getStateId().equals("2")) {
                buttonAdd.setBackgroundResource(BTN_COMMIT_BG[1]);
            } else if (btnViewEntityList.get(i).getStateId().equals("3")) {
                buttonAdd.setBackgroundResource(BTN_COMMIT_BG[2]);
            } else {
                buttonAdd.setBackgroundResource(R.color.gray_efefef);
            }
            buttonAdd.setText(btnViewEntityList.get(i).getBtnText());
            buttonAdd.setTag(btnViewEntityList.get(i).getBtnId());
            buttonAdd.setTextColor(ContextCompat.getColor(context, R.color.white));
            buttonAdd.setTextSize(14);

            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
            params.weight = 1;
            params.leftMargin = 1;
            params.rightMargin = 1;
            buttonAdd.setPadding(10, 0, 10, 0);
            buttonAdd.setLayoutParams(params);
            layout.addView(buttonAdd);
            buttonAdd.setOnClickListener(mListener);
        }
        viewGroup.addView(layout);
    }

   public static class BtnViewEntity {
        private String btnText;
        private String btnId;
        private String stateId;

        public BtnViewEntity(String btnText, String btnId) {
            this.btnText = btnText;
            this.btnId = btnId;
        }

        public BtnViewEntity(String btnText, String btnId, String stateId) {
            this.btnText = btnText;
            this.btnId = btnId;
            this.stateId = stateId;
        }

        public String getStateId() {
            return stateId;
        }

        public void setStateId(String stateId) {
            this.stateId = stateId;
        }

        public String getBtnText() {
            return btnText;
        }

        public void setBtnText(String btnText) {
            this.btnText = btnText;
        }

        public String getBtnId() {
            return btnId;
        }

        public void setBtnId(String btnId) {
            this.btnId = btnId;
        }
    }
}
